package com.jic.market.common.enums;

import java.util.EnumSet;

/**
 * @author : xuyongliang
 * @date : 2020/3/3 7:51 PM
 * @description: 10-SPU;20-SKU
 * @modified By:
 * @version: V1.0
 */
public enum TypeOfProductEnum {

    // 1-普通商品;2-系列子品
    @Deprecated
    NORMAL(1, "普通商品"),
    @Deprecated
    SUB_SERIES(2, "系列子品"),
    @Deprecated
    MAIN_SERIES(3, "系列主品"),

    GOODS_SPU(10,"SPU"),
    GOODS_SKU(20,"SKU"),
    ;

    private Integer code;

    private String value;

    TypeOfProductEnum(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public static TypeOfProductEnum getEnumByCode(Integer code){
        EnumSet<TypeOfProductEnum> elements = EnumSet.allOf(TypeOfProductEnum.class);
        for(TypeOfProductEnum enumType : elements){
            if(enumType.getCode().equals(code)){
                return enumType;
            }
        }
        return null;
    }

    public static int getCodeByValue(String value) {
        for (TypeOfProductEnum c : TypeOfProductEnum.values()) {
            if (c.getValue().equals(value.trim())) {
                return c.code;
            }
        }
        return 0;
    }

    public static String getValue(Integer code) {
        return getEnumByCode(code).getValue();
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getValue() {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }
}
